home *** CD-ROM | disk | FTP | other *** search
- '********************************BOXDRAW.BAS******************************
- '
- ' a program I HAD to make for my own use as I couldn't find one that I could
- ' understand. A program to draw boxes on the screen in text mode using a
- ' SUB that you call with the box size, box line draw and box colors.
- ' Run it as a demo first and then add a box to one of your own programs.
- ' I have purposely put the variables on a line BEFORE the BOXDRAW1 SUB
- ' is called so that it is harder to mess up the CALL.
- '
- ' If you like this program, let me know. If you make it better, give me
- ' a copy. If you don't like it, tell me why.
- '
- ' John De Palma on CompuServe 76076,571
- ' October 23, 1992
- '**************************************************************************
- DEFINT A-Z
- DECLARE SUB boxdraw1 (top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
-
- ' giving the color numbers names makes it easier to display and correct.
- CONST black = 0
- CONST blue = 1
- CONST green = 2
- CONST cyan = 3
- CONST red = 4
- CONST magenta = 5
- CONST brown = 6
- CONST grey = 7 'don't use above 7 for background
- CONST bright = 8
- CONST white = 15 'added this
- CONST blink = 16
- CONST yellow = 14 'or use brown + bright
- DO 'outside loop
- CLS
- top = 1: bottom = 25: left = 1: right = 80: lines = 1: forecolor = white: backcolor = blue
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- LOCATE 1, 6: PRINT "Press a key to cycle the demo; PRESS <Esc> at the last screen to EXIT"
-
- DO UNTIL LEN(INKEY$) 'press a key to go on
- LOOP
- PLAY "p32" 'a little multimedia
- top = 2: bottom = 10: left = 2: right = 30: lines = 0: forecolor = yellow: backcolor = brown
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- DO UNTIL LEN(INKEY$)
- LOOP
- PLAY "p32"
-
- top = 9: bottom = 18: left = 15: right = 35: lines = 1: forecolor = blue: backcolor = grey
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- DO UNTIL LEN(INKEY$)
- LOOP
- PLAY "p32"
-
- top = 10: bottom = 15: left = 40: right = 50: lines = 2: forecolor = red: backcolor = black
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- DO UNTIL LEN(INKEY$)
- LOOP
- PLAY "p32"
-
- top = 2: bottom = 12: left = 50: right = 79: lines = 3: forecolor = white: backcolor = green
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- DO UNTIL LEN(INKEY$)
- LOOP
- PLAY "p32"
-
- top = 12: bottom = 24: left = 2: right = 22: lines = 4: forecolor = yellow: backcolor = red
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- DO UNTIL LEN(INKEY$)
- LOOP
- PLAY "p32"
-
- top = 6: bottom = 10: left = 30: right = 50: lines = 5: forecolor = bright + cyan: backcolor = cyan
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
- DO UNTIL LEN(INKEY$)
- LOOP
- PLAY "p32"
-
- 'it looks hard but it's really easy to draw a "shadowed box."
- 'all you have to do is first draw a box down and to the right (or left)
- 'of your display box using a black background and grey foreground.
- 'then call the display box.
- 'first the shadow....
-
- top = 18: bottom = 24: left = 12: right = 74: lines = 0: forecolor = grey: backcolor = black
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
-
-
- 'then the display box...
-
- top = 17: bottom = 23: left = 10: right = 70: lines = 2: forecolor = white: backcolor = cyan
- CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
-
- LOCATE 18, 15: PRINT "This is the last screen. Note this is a shadow box."
- LOCATE 19, 15: PRINT "I hope you find this program as much fun to use"
- LOCATE 20, 15: PRINT "as I had in developing it. This program makes free"
- LOCATE 21, 15: PRINT "use of public code and stuff from other programs."
- LOCATE 23, 22: PRINT "John De Palma on CompuServe 76076,571"
-
- 'If you really, really want to impress your friends then you may want
- 'to have a "see through" shadow. You will have to redraw the
- 'portion of the box covered by the shadow and that is harder
- 'if you are layering boxes as you go. The following code snippet will
- 'give you an idea on how to manually do this.
- LOCATE 24, 12: COLOR grey, black: PRINT STRING$(11, 223);
-
- DO UNTIL LEN(INKEY$) 'must be some key strokes
- IF INKEY$ = CHR$(27) THEN SYSTEM 'left in the buffer as
- LOOP 'you need a double escape
- PLAY "p32" 'occasionally to get out
- 'of this program
- WHILE INKEY$ = ""
- IF INKEY$ = CHR$(27) THEN SYSTEM
- WEND
- PLAY "p32"
-
- LOOP
- SYSTEM
-
- DEFSNG A-Z
- SUB boxdraw1 (toprow%, bottomrow%, leftcolumn%, rightcolumn%, outline%, fgd%, bkgd%)
-
- ' This routine draws and colors text boxes using color and line draw.
- ' If outline% is set to 5, prints thick horizontal bars, top & bottom rows.
- ' If outline% is set to 4, prints a bold-lined box
- ' If outline% is set to 3, prints a double sided box
- ' If outline% is set to 2, prints double top and single sided box.
- ' If outline% is set to 1, prints a single sided box.
- ' If outline% is set to 0, prints a box with no outline.
-
- 'this sets the colors
- COLOR fgd%, bkgd%
-
- middle% = rightcolumn% - leftcolumn%
- lines% = toprow%
- boxside$ = CHR$(186) 'double line
- boxside3$ = CHR$(179) 'single line
- boxside4$ = CHR$(219) 'bold line
-
- boxtop% = (rightcolumn% - leftcolumn%) - 1
-
- boxtop$ = CHR$(201) + STRING$(boxtop%, 205) + CHR$(187) 'double line
- boxtop2$ = CHR$(213) + STRING$(boxtop%, 205) + CHR$(184) 'double top, single side
- boxtop3$ = CHR$(218) + STRING$(boxtop%, 196) + CHR$(191) 'single line
- boxtop4$ = CHR$(220) + STRING$(boxtop%, 220) + CHR$(220) 'bold line
-
- boxbottom$ = CHR$(200) + STRING$(boxtop%, 205) + CHR$(188) 'double line
- boxbottom2$ = CHR$(212) + STRING$(boxtop%, 205) + CHR$(190) 'double bottom, single side
- boxbottom3$ = CHR$(192) + STRING$(boxtop%, 196) + CHR$(217) 'single line
- boxbottom4$ = CHR$(223) + STRING$(boxtop%, 223) + CHR$(223) 'bold line
-
- midbox$ = STRING$(boxtop% + 1, 219)
-
- 'this prints the box
-
- FOR boxsize% = toprow% TO bottomrow%
- LOCATE lines%, leftcolumn%, 0
- PRINT SPACE$(middle%);
- lines% = lines% + 1
- NEXT
-
- 'this prints the box outline
-
- SELECT CASE outline%
-
- CASE 0
- EXIT SUB
-
- CASE 1
-
- LOCATE toprow%, leftcolumn%
- PRINT boxtop3$;
- FOR outline% = toprow% + 1 TO bottomrow% - 1
- LOCATE outline%, leftcolumn%
- PRINT boxside3$;
- LOCATE outline%, rightcolumn%
- PRINT boxside3$;
- NEXT outline%
- LOCATE bottomrow%, leftcolumn%
- PRINT boxbottom3$;
-
- CASE 2
-
- LOCATE toprow%, leftcolumn%
- PRINT boxtop2$;
- FOR outline% = toprow% + 1 TO bottomrow% - 1
- LOCATE outline%, leftcolumn%
- PRINT boxside3$;
- LOCATE outline%, rightcolumn%
- PRINT boxside3$;
- NEXT outline%
- LOCATE bottomrow%, leftcolumn%
- PRINT boxbottom2$;
-
- CASE 3
-
- LOCATE toprow%, leftcolumn%
- PRINT boxtop$;
- FOR outline% = toprow% + 1 TO bottomrow% - 1
- LOCATE outline%, leftcolumn%
- PRINT boxside$;
- LOCATE outline%, rightcolumn%
- PRINT boxside$;
- NEXT outline%
- LOCATE bottomrow%, leftcolumn%
- PRINT boxbottom$;
-
- CASE 4
-
- LOCATE toprow%, leftcolumn%
- PRINT boxtop4$;
- FOR outline% = toprow% + 1 TO bottomrow% - 1
- LOCATE outline%, leftcolumn%
- PRINT boxside4$;
- LOCATE outline%, rightcolumn%
- PRINT boxside4$;
- NEXT outline%
- LOCATE bottomrow%, leftcolumn%
- PRINT boxbottom4$;
-
- CASE 5
-
- LOCATE toprow%, leftcolumn%: PRINT midbox$;
- LOCATE bottomrow%, leftcolumn%: PRINT midbox$;
- END SELECT
- END SUB
-
-